//增加
function add() {
    layui.use(['form','jquery'], () => {
        let  form = layui.form;
        let  $ = layui.jquery;
        form.on('submit(campus-increase-save)', function (data) {
            var campusData = data.field;
            $.ajax({
                url : MODULE_PATH + 'basedata.campus/add',
                type : "POST",
                dataType : "json",
                data : campusData,
                success : function (res) {
                    if (res.code == 200) {
                        //关闭弹窗
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        //form重置
                        $('#campus-increase-form')[0].reset();
                    }
                    //调用父页面的结果提示
                    parent.result(res.code,res.msg);
                }
            });
            return false;
        });
    });
}

//修改
function edit(id = null) {
    layui.use(['form','jquery'], () => {
        let  form = layui.form;
        let  $ = layui.jquery;

        //判断id是否存在
        if (id == null) layer.msg('指针不存在', {
            shade: 0.4,
            icon: 2,
            time: 1000
        });

        form.on('submit(campus-increase-save)', (data) => {
            var campusData = data.field;
            campusData.id = id;
            $.ajax({
                url : MODULE_PATH + 'basedata.campus/edit',
                type : "POST",
                dataType : "json",
                data : campusData,
                success : function (res) {
                    if (res.code == 200) {
                        //关闭弹窗
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        //form重置
                        $('#campus-increase-form')[0].reset();
                    }
                    //调用父页面的结果提示
                    parent.result(res.code,res.msg);
                }
            });
            return false;
        });
    });
}